﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MusteriTakipProgrami
{
    public partial class UrunListele : Form
    {

        SatisKayit spen;
        public UrunListele(SatisKayit sk)
        {
            spen = sk;
            InitializeComponent();
        }

        private void UrunListele_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'mUSTERITAKIPDataSet5.URUN' table. You can move, or remove it, as needed.
            this.uRUNTableAdapter.Fill(this.mUSTERITAKIPDataSet5.URUN);

            


        }
        public DataGridView dgv;

        private void SecDon_Btn_Click(object sender, EventArgs e)
        {
            this.Close();
            

        }

        private void hucreyeTiklaninca(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                string str = "";
                for (int i = 0; i < UrunListele_DGV.RowCount; i++)
                {
                    DataGridViewCheckBoxCell ch = UrunListele_DGV[0, i] as DataGridViewCheckBoxCell;

                    

                    if ((bool)ch.EditedFormattedValue == true)
                    {
                        str += UrunListele_DGV[1, i].Value.ToString() + ",";
                    }
                }
                if (str.Length > 0) {
                    str = str.Substring(0, str.Length - 1);
                    string sql = "select * from urun where ID in (" + str + ")";
                    SqlConnection sc = new SqlConnection("server=.;database=MUSTERITAKIP;trusted_connection=true");
                    SqlDataAdapter adpt = new SqlDataAdapter(sql, sc);
                    DataTable dt = new DataTable();
                    adpt.Fill(dt);
                    spen.dataGridView1.DataSource = dt;
                    
                }
            }
        }

        private void urunAraToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.uRUNTableAdapter.UrunAra(this.mUSTERITAKIPDataSet5.URUN, ((int)(System.Convert.ChangeType(iDToolStripTextBox.Text, typeof(int)))), uRUN_ADIToolStripTextBox.Text);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

    }
}
